import { getZone, updateZone } from '../../../api/user'

Page({
  data: {
    intro: '',
    goodAt: '',
    goodAtLabels: [],
    growUpSpecialityShow: '',
    honour: '',
    trainSpeciality: '',
    trainSpecialityLabels: []
  },
  onLoad: function (options) {
    this.init()
  },
  init() {
    getZone().then(res => {
      this.setData({
        intro: res.intro,
        goodAt: res.goodAt,
        goodAtLabels: res.goodAtLabels,
        growUpSpecialityShow: res.growUpSpecialityShow,
        honour: res.honour,
        trainSpeciality: res.trainSpeciality,
        trainSpecialityLabels: res.trainSpecialityLabels
      })
    })
  },
  editIntro() {
    this.editInfo({
      title: '介绍',
      data: this.data.intro,
      name: 'intro'
    })
  },
  editGoodAt() {
    this.editLabels({
      title: '学科教学专长',
      name: 'goodAt',
      subName: 'goodAtLabels'
    })
  },
  editGrowUp() {
    this.editInfo({
      title: '教师成长专长介绍',
      data: this.data.growUpSpecialityShow,
      name: 'growUpSpecialityShow'
    })
  },
  editTrainSpeciality() {
    this.editLabels({
      title: '教师成长专长',
      name: 'trainSpeciality',
      subName: 'trainSpecialityLabels'
    })
  },
  editHonour() {
    wx.navigateTo({
      url: '/packageA/pages/personalHonourEdit/personalHonourEdit'
    })
  },
  editInfo({ title, data, name }) {
    getApp().globalData[name] = data
    wx.navigateTo({
      url: '/packageA/pages/personalEditor/personalEditor?title=' + title + '&name=' + name
    })
  },
  editLabels({ title, name, subName}) {
    wx.navigateTo({
      url: '/packageA/pages/personalSpaceEdit/personalSpaceEdit?title=' + title + '&name=' + name + '&subName=' + subName
    })
  }
})
